﻿@page "/DateRangePicker/Preset-Ranges"

@using Syncfusion.Blazor.Calendars

@inherits SampleBaseComponent;

<SampleDescription>
    <p>Click/Touch the DateRangePicker popup icon to view and select the list of custom preset ranges. Select the custom range option which is provided at the end of this list to open date range picker popup calendar for selecting custom ranges.</p>
</SampleDescription>
<ActionDescription>
    <p>The <code>DateRangePicker</code> component has presets support to display the collection of required ranges in the popup element. User can select a required range from the list and the selected range value will be updated in the component.</p>
</ActionDescription>

<div class="control-section">
    <div id="wrapper">
        <div class="wrap">
            <SfDateRangePicker TValue="DateTime?" Placeholder="Choose a Range">
                <DateRangePickerPresets>
                    <DateRangePickerPreset Label="This Week" Start="@WeekStart" End="@WeekEnd"></DateRangePickerPreset>
                    <DateRangePickerPreset Label="This Month" Start="@MonthStart" End="@MonthEnd"></DateRangePickerPreset>
                    <DateRangePickerPreset Label="Last Month" Start="@LastMonthStart" End="@LastMonthEnd"></DateRangePickerPreset>
                    <DateRangePickerPreset Label="Last Year" Start="@LastYearStart" End="@LastYearEnd"></DateRangePickerPreset>
                </DateRangePickerPresets>
            </SfDateRangePicker>
        </div>
    </div>
</div>

<style>
    #wrapper {
        max-width: 300px;
        margin: 0px auto;
        padding-top: 20px;
    }
</style>

@code {
    private DateTime LastMonth { get; set; }
    private DateTime WeekStart { get; set; }
    private DateTime WeekEnd { get; set; }
    private DateTime MonthStart { get; set; }
    private DateTime MonthEnd { get; set; }
    private DateTime LastMonthStart { get; set; }
    private DateTime LastMonthEnd { get; set; }
    private DateTime LastYearStart { get; set; }
    private DateTime LastYearEnd { get; set; }
    private int Days { get; set; }

    protected override void OnInitialized()
    {
        Days = (int)DateTime.Now.DayOfWeek;
        LastMonth = DateTime.Now.AddMonths(-1);
        WeekStart = DateTime.Now.AddDays(-Days);
        WeekEnd = WeekStart.AddDays(6);
        MonthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
        MonthEnd = MonthStart.AddMonths(1).AddDays(-1);
        LastMonthStart = new DateTime(LastMonth.Year, LastMonth.Month, 1);
        LastMonthEnd = LastMonthStart.AddMonths(1).AddDays(-1);
        LastYearStart = new DateTime(DateTime.Now.Year - 1, 1, 1);
        LastYearEnd = new DateTime(DateTime.Now.Year - 1, 12, 31);
    }
}
